/**
 *
 */
package org.fixies.utils;

import java.util.HashMap;
import java.util.NoSuchElementException;

/**
 * @author Kawasaki
 * @version 1.0
 */
public class NullValueAvoidingHashMap<K, V> extends HashMap<K, V> {

    private static final long serialVersionUID = 1L;

    /*
     * (non-Javadoc)
     * 
     * @see java.util.HashMap#get(java.lang.Object)
     */

    @Override
    public V get(Object key) {
        if (!containsKey(key)) {
            String msg = "key does not exist. argument key = [" + key + "] this =[" + this + "]";
            throw new NoSuchElementException(msg);
        }
        return super.get(key);
    }

    /*
     * (non-Javadoc)
     * 
     * @see java.util.HashMap#put(java.lang.Object, java.lang.Object)
     */

    @Override
    public V put(K key, V value) {
        if (value == null) {
            throw new IllegalArgumentException("cant put null value. key=[" + key + "]");
        }
        return super.put(key, value);
    }

}
